/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery","promise"],function(a,g){a.ka=a.Events={on:function(a,c,d){return this.Zp(a,c,d,!1,!1)},off:function(a,c,d){return this.IV(a,c,d,!1)},trigger:function(b){var c=Array.prototype.slice.call(arguments);c.unshift(!1);return a.ka.Kc.apply(this,c)},once:function(a,c,d){return this.Yaa(a,c,d,!1,null)},listenTo:function(b,c,d){var e,f,h,k,g={};c.constructor===String?g[c]=d:g=c;for(k in g)if(g.hasOwnProperty(k))for(c=a.ka.wv(k),d=0;d<c.length;d+=1)e=c[d].event,f=c[d].ha,h={event:e,
ha:f,object:b,Mc:g[k]},this.PR(this._listeningTo,h,a.ka.qaa),e=f?e+":"+f:e,void 0===this._listeningTo&&(this._listeningTo=[]),this._listeningTo.push(h),b.Zp(e,g[k],null,!0,!1);return this},listenToOnce:function(b,c,d){var e,f,h,k,g={};c.constructor===String?g[c]=d:g=c;for(k in g)if(g.hasOwnProperty(k))for(c=a.ka.wv(k),d=0;d<c.length;d+=1)e=c[d].event,f=c[d].ha,h={event:e,ha:f,object:b,Mc:g[k]},this.PR(this._listeningTo,h,a.ka.qaa),e=f?e+":"+f:e,void 0===this._listeningTo&&(this._listeningTo=[]),this._listeningTo.push(h),
b.Yaa(e,g[k],null,!0,this);return this},stopListening:function(b,c,d){var e,f={},h,k,g,m,r,t,s,q,p;if(null==arguments||1>=arguments.length){t=this._listeningTo?this._listeningTo.length:0;for(q=0;q<t;q++)if(m=this._listeningTo[q],r=b?b===m.object:!0)r=m.object.IV,r.apply(m.object,[m.event,m.Mc,m.context,!0]);this._listeningTo=[];return this}e=c;b&&b.constructor===String&&(e=b);e.constructor===String?f[e]=d:f=e;for(p in f)if(f.hasOwnProperty(p))for(e=a.ka.wv(p),h=0;h<e.length;h+=1)for(k=e[h].event,
g=e[h].ha,t=this._listeningTo?this._listeningTo.length:0,q=t-1;0<=q;q-=1)m=this._listeningTo[q],r=b?b===m.object:!0,t=k?k===m.event:!0,s=d?f[p]===m.Mc:!0,m=g?g===m.ha:!0,r&&t&&s&&m&&(r=this._listeningTo[q].object.IV,r.apply(this._listeningTo[q].object,[this._listeningTo[q].event,this._listeningTo[q].Mc,this._listeningTo[q].context,!0]),this._listeningTo.splice(q,1));return this}};a.ka.bind=a.ka.on;a.ka.unbind=a.ka.off;a.ka.O={ADD:"add",ALLADDED:"alladded",REMOVE:"remove",RESET:"reset",REFRESH:"refresh",
SORT:"sort",CHANGE:"change",DESTROY:"destroy",ALLREMOVED:"allremoved",REQUEST:"request",SYNC:"sync",ERROR:"error",INVALID:"invalid",READY:"ready",ALL:"all"};o_("Events.EventType",a.ka.O,a);a.ka.jP=function(a,c){var d,e=c||this;for(d in e)"function"===typeof e[d]&&(a[d]=e[d]);a.Pe={};a._listeningTo=[]};a.ka.Yaa=function(a,c,d,e,f){var h,k,g,m;g=this.rT(a,c);for(m in g)if(g.hasOwnProperty(m))for(a=this.wv(m),c=0;c<a.length;c+=1)h=a[c].event,k=a[c].ha,void 0===this.Pe&&(this.Pe=[]),void 0===this.Pe[h]&&
(this.Pe[h]=[]),this.Pe[h].push({Mc:g[m],context:d,ha:k,Cr:!0,fired:!1,It:e,mG:f});return this};a.ka.zda=function(a){return a.Cr?a.fired?!1:a.fired=!0:!0};a.ka.F7=function(a,c){return c.context||c.mG||a};a.ka.Kc=function(b,c){var d=this.wv(c),e,f,h,k,g,m;k=[];for(e=0;e<d.length;e+=1)f=d[e].event,h=d[e].ha,k.push({event:f,ha:h});for(e=0;e<k.length;e+=1){g=this.yJ(this.Pe,a.ka.O.ALL);d=a.ka.yJ(this.Pe,k[e].event,!1);for(f=0;f<(d?d.length:0);f+=1)d[f].ha===k[e].ha&&d[f].Mc&&(h=Array.prototype.slice.call(arguments),
d&&d[f]&&d[f].Cr&&(this.bca(a.ka.yJ(this.Pe,k[e].event,!0),d[f]),d[f].mG&&d[f].mG.stopListening(this,c,d[f].Mc)),d&&d[f]&&this.zda(d[f])&&(m=d[f].Mc,b&&!d[f].Jha||m.apply(a.ka.F7(this,d[f]),h.slice(2))));for(f=0;f<(g?g.length:0);f+=1)h=Array.prototype.slice.call(arguments),0<h.length&&(h[1]=k[e].ha?k[e].event+":"+k[e].ha:k[e].event),g&&g[f]&&g[f].Mc&&this.zda(g[f])&&(m=g[f].Mc,b&&!g[f].Jha||m.apply(a.ka.F7(this,g[f]),h.slice(1))),g&&g[f]&&g[f].Cr&&(this.bca(this.yJ(this.Pe,a.ka.O.ALL,!0),g[f]),g[f].mG&&
g[f].mG.stopListening(this,a.ka.O.ALL,g[f].Mc))}return this};a.ka.Zp=function(b,c,d,e,f){var h,k,g,m;b=this.rT(b,c);for(h in b)if(b.hasOwnProperty(h))for(c=this.wv(h),k=0;k<c.length;k+=1)g=c[k].event,m=c[k].ha,void 0===this.Pe&&(this.Pe=[]),void 0===this.Pe[g]&&(this.Pe[g]=[]),m={Mc:b[h],context:d,ha:m,It:e,Jha:f},-1===this.PR(this.Pe[g],m,a.ka.lya)&&this.Pe[g].push(m);return this};a.ka.IV=function(a,c,d,e){var f,h;if(null==arguments||0==arguments.length)return this.Pe={},this;if(null==a)return this.aca(a,
c,d,e),this;f=this.rT(a,c);for(h in f)f.hasOwnProperty(h)&&this.aca(h,f[h],d,e);return this};a.ka.rT=function(a,c){var d={};a.constructor===String?d[a]=c:d=a;return d};a.ka.aca=function(b,c,d,e){var f=[],h,k,g,m,r,t,s,q;if(b)f=a.ka.wv(b);else if(void 0!==this.Pe)for(k in this.Pe)this.Pe.hasOwnProperty(k)&&f.push({event:k});for(b=0;b<f.length;b+=1)if(k=f[b].event,g=f[b].ha,void 0!==this.Pe&&this.Pe[k]instanceof Array){m=this.Pe[k];for(h=m.length-1;0<=h;h-=1)r=void 0===c||null===c||m[h].Mc==c,t=void 0===
d||null===d||m[h].context==d,s=void 0===g||null===g||m[h].ha==g,q=void 0===e||null===e||m[h].It==e,r&&t&&s&&q&&m.splice(h,1);0===m.length&&delete this.Pe[k]}};a.ka.bca=function(a,c){var d,e,f,h,k,g;if(a)for(d=a.length-1;0<=d;d-=1)e=void 0===c.Mc||null===c.Mc||a[d].Mc==c.Mc,f=void 0===c.context||null===c.context||a[d].context==c.context,h=void 0===c.ha||null===c.ha||a[d].ha==c.ha,k=void 0===c.It||null===c.It||a[d].It==c.It,g=void 0===c.Cr||null===c.Cr||a[d].Cr==c.Cr,e&&f&&h&&k&&g&&a.splice(d,1)};a.ka.wv=
function(a){a=a?a.split(" "):[];var c=[],d,e,f;for(d=0;d<a.length;d+=1)e=a[d].split(":"),f=e[0],e=1<e.length?e[1]:null,c.push({event:f,ha:e});return c};a.ka.lya=function(a,c){return a.Mc===c.Mc&&a.ha===c.ha&&a.context===c.context&&a.It===c.It&&a.Cr===c.Cr};a.ka.qaa=function(a,c){return a.event===c.event&&a.ha===c.ha&&a.context===c.context&&a.object===c.object};a.ka.PR=function(a,c,d){var e;if(void 0===a)return-1;for(e=0;e<a.length;e+=1)if(d(a[e],c))return e;return-1};a.ka.yJ=function(a,c,d){if(a&&
a[c]instanceof Array){if(d)return a[c];d=[];var e;for(e=0;e<a[c].length;e++)d.push(a[c][e]);return d}return null};a.C=function(b,c){a.C._init(this,b,c,null)};o_("Model",a.C,a);a.b.sa(a.C,a.b,"oj.Model");a.C.prototype.Init=function(){a.C.u.Init.call(this)};a.C.prototype.attributes={};a.b.g("Model.prototype.attributes",{attributes:a.C.prototype.attributes});a.C.prototype.Xc={};a.b.g("Model.prototype.defaults",{Xc:a.C.prototype.Xc});a.C.prototype.id=null;a.b.g("Model.prototype.id",{id:a.C.prototype.id});
a.C.prototype.Iha="id";a.b.g("Model.prototype.idAttribute",{Iha:a.C.prototype.Iha});a.C.prototype.Ika=null;a.b.g("Model.prototype.urlRoot",{Ika:a.C.prototype.Ika});a.C.prototype.En=null;a.b.g("Model.prototype.customURL",{En:a.C.prototype.En});a.C.prototype.validate=null;a.b.g("Model.prototype.validate",{validate:a.C.prototype.validate});a.C.prototype.Jka=null;a.b.g("Model.prototype.validationError",{Jka:a.C.prototype.Jka});a.C.TU=0;a.C._init=function(b,c,d,e){var f=null,h;if(!a.C.UD){b.Init();a.ka.jP(b);
b.uy();b.m_={};b.YN=!1;b.index=-1;d=d||{};b.attributes={};b.defaults&&!d.xJa&&(b.attributes=a.C.yI(g.isFunction(b.defaults)?b.defaults():b.defaults,null));for(f in e)e.hasOwnProperty(f)&&(b[f]=e[f]);if(c)if(e=d.parse,g.isFunction(e)&&(b.parse=e),h=a.C.yI(c,b.attributes),h=e?b.parse(h):h,null==h||void 0===h)b.attributes={};else for(f in h)h.hasOwnProperty(f)&&b.JW(f,h[f],!1,!1,d);b.$G();b.HB(d.collection);d.customURL&&(b.customURL=d.customURL);d.url&&(b.url=d.url);d.urlRoot&&(b.urlRoot=d.urlRoot);
b.initialize&&b.initialize(c,d);b.io()}};a.C.extend=function(b,c){a.C.UD=!0;var d,e;d=new a.C;a.C.UD=!1;g.extend(d,this.prototype);b=b||{};for(e in b)b.hasOwnProperty(e)&&(d[e]=b[e]);var f;f=b&&b.constructor&&b.hasOwnProperty("constructor")?b.constructor:function(c,d){a.C._init(this,c,d,b)};g.extend(f,this);f.prototype=d;f.extend=a.C.extend;f.prototype.constructor=f;a.ka.jP(f,this);if(c)for(e in c)c.hasOwnProperty(e)&&(f[e]=c[e]);return f};o_("Model.extend",a.C.extend,a);a.C.prototype.Kc=function(){};
a.C.prototype.$G=function(){this.zu()||(this.cid="id"+a.C.TU,a.C.TU+=1)};a.C.prototype.zu=function(){return this.cid};a.C.prototype.IB=function(a){this.index=a};a.C.prototype.pla=function(){return this.index};a.C.prototype.vP=function(a){this.pKa=a};a.C.prototype.aH=function(a){var c=this.n_;this.n_=a;return c};a.C.prototype.Gla=function(b,c,d){var e,f=!1,h=a.cb.Re(c),k,g=!1;for(e in b.attributes)b.attributes.hasOwnProperty(e)&&(k=this.attributes[e]!=b.attributes[e],h?e===c&&k&&(f=!0):k&&(f=!0),k&&
(g=!0,this.attributes[e]=b.attributes[e],this.bR(e,b.attributes[e]),this.bJ(e,this.attributes[e],null,d)));this.io();g&&this.cJ(null,d);return f};a.C.eK=function(a){var c;if(a&&a instanceof Object)for(c in a)if(a.hasOwnProperty(c))return!0;return!1};a.C.prototype.HB=function(a){null==a?delete this.collection:(this.collection=a,this.io())};a.C.prototype.uB=function(){return this.collection};a.C.prototype.bJ=function(b,c,d,e){null!=b&&this.Kc(e,a.ka.O.CHANGE+":"+b,this,c,d)};a.C.prototype.cJ=function(b,
c){this.Kc(c,a.ka.O.CHANGE,this,b,null)};a.C.prototype.io=function(){var a=null;this.collection&&this.collection.modelId&&(a=this.collection.modelId,a=g.isFunction(a)?a.call(this.collection,this.attributes):a);a||(a=this.wT(),a=null!=this.attributes?this.attributes[a]:null);this.id=a};a.C.prototype.dEa=function(b,c,d){var e=a.b.kC(this.attributes[b],c);return d||!e?(this.attributes[b]=c,this.io(),!e):!1};a.C.prototype.uy=function(){this.changed={}};a.C.prototype.bR=function(a,c){this.changed[a]=c};
a.C.prototype.JW=function(b,c,d,e,f){if(null==b)return!0;var h={},k,g=this.YN;if(e)for(k in b)b.hasOwnProperty(k)&&(h[k]=b[k]);else h[b]=c;b=f||{};if(!this.CC(h,{validate:b.validate},!1))return!1;g||(this.uy(),this.wt=[]);this.YN||(this.m_=a.C.yI(this.attributes,null));this.YN=!0;for(k in h)h.hasOwnProperty(k)&&(this.dEa(k,h[k],d)?(this.bR(k,h[k]),this.wt.push(k)):delete h[k]);d=b.silent;for(k in h)h.hasOwnProperty(k)&&(!d&&(0<this.wt.length||g&&-1===this.wt.indexOf(k))&&(this.jja=!0,this.AKa=b),
this.bJ(k,h[k],b,d));if(g)return!0;if(!d&&!g)for(;this.jja;)this.jja=!1,this.cJ(this.AKa,d);this.YN=!1;return!0};a.C.prototype.clear=function(b){var c,d={silent:!0},e;b=b||{};e=b.silent;d.validate=b.validate;this.uy();for(c in this.attributes)if(this.attributes.hasOwnProperty(c)){if(!this.QL(c,d,!0))return!1;this.Kc(e,a.ka.O.CHANGE+":"+c,this,void 0,null)}this.attributes={};this.io();this.bJ(null,null,null,e);this.cJ(null,e);return this};a.b.g("Model.prototype.clear",{clear:a.C.prototype.clear});
a.C.yI=function(b,c){c=c||{};for(var d in b)c.hasOwnProperty(d)&&b.hasOwnProperty(d)&&void 0===b[d]&&delete b[d];a.Uc.yf(c,b,void 0,!0,1E4);return c};a.C.prototype.clone=function(){var b=new this.constructor,c;for(c in this)this.hasOwnProperty(c)&&this[c]!==this.attributes&&(b[c]=this[c]);b.attributes=a.C.yI(this.attributes,null);delete b.cid;b.$G();b.io();return b};a.b.g("Model.prototype.clone",{clone:a.C.prototype.clone});a.C.prototype.Gu=function(a,c){var d=this.Mi();if(void 0!==d&&d==a)return!0;
d=this.cid;return void 0!==d&&d==c?!0:!1};a.C.prototype.set=function(b,c,d){var e=d||{},f,h=!0;if(arguments&&0<arguments.length)if(a.cb.Re(b))e.unset?this.QL(b,null,!1):this.JW(b,c,!1,!1,e)||(h=!1);else if(e=c||{},e.unset)for(f in b)b.hasOwnProperty(f)&&this.QL(f,null,!1);else this.JW(b,null,!0,!0,e)||(h=!1);return h?this:!1};a.b.g("Model.prototype.set",{set:a.C.prototype.set});a.C.prototype.Gka=function(a,c){return this.QL(a,c,!1)};a.b.g("Model.prototype.unset",{Gka:a.C.prototype.Gka});a.C.prototype.QL=
function(a,c,d){c=c||{};var e=c.silent,f={};if(this.has(a)){if(!this.CC(f,c,!1))return!1;d||this.uy();delete this.attributes[a];this.bR(a,void 0);this.bJ(a,null,null,e);this.cJ(null,e)}this.io();return!0};a.C.prototype.get=function(a){return this.attributes[a]};a.b.g("Model.prototype.get",{get:a.C.prototype.get});a.C.prototype.has=function(b){return a.l.wq(this.attributes[b])};a.b.g("Model.prototype.has",{has:a.C.prototype.has});a.C.prototype.fetch=function(b){b=b||{};var c=b.success,d=b.error,e=
this,f;f=a.C.iv(b);f.error=function(c,k,f){a.C.YE(e,!1,b,k,f,c);d&&d.apply(e,arguments)};f.success=function(d){f.xhr&&(b.xhr=f.xhr);a.C.fJ(e,d,f);g.isFunction(e.parse)&&e.set(e.parse(d),f);c&&c.call(a.C.vl(f,e),e,d,b)};return a.C.GD("read",this,f)};a.b.g("Model.prototype.fetch",{fetch:a.C.prototype.fetch});a.C.prototype.parse=function(a){return a};a.C.prototype.url=function(){var b=this.h9(),c=this.Mi();if(b)return c?b+"/"+encodeURIComponent(c):b;if(b=this.collection)return b=a.C.Sr(b,"url"),c&&b?
(c="/"==a.C.gva(b)?"":"/",b+c+encodeURIComponent(this.Mi())):b;throw new a.Xr;};a.b.g("Model.prototype.url",{url:a.C.prototype.url});a.C.prototype.keys=function(){var a,c=[];for(a in this.attributes)this.attributes.hasOwnProperty(a)&&c.push(a);return c};a.b.g("Model.prototype.keys",{keys:a.C.prototype.keys});a.C.prototype.Lka=function(){var a,c=[];for(a in this.attributes)this.attributes.hasOwnProperty(a)&&c.push(this.get(a));return c};a.b.g("Model.prototype.values",{Lka:a.C.prototype.Lka});a.C.prototype.hja=
function(){var a,c=[],d;for(a in this.attributes)this.attributes.hasOwnProperty(a)&&(d=[],d.push(a),d.push(this.get(a)),c.push(d));return c};a.b.g("Model.prototype.pairs",{hja:a.C.prototype.hja});a.C.prototype.dja=function(a){var c=[],d,e,f={};if(a instanceof Array)c=a;else for(d=0;d<arguments.length;d++)c.push(arguments[d]);for(e in this.attributes)this.attributes.hasOwnProperty(e)&&-1==c.indexOf(e)&&(f[e]=this.get(e));return f};a.b.g("Model.prototype.omit",{dja:a.C.prototype.dja});a.C.prototype.kja=
function(a){var c=[],d,e={};if(a instanceof Array)c=a;else for(d=0;d<arguments.length;d++)c.push(arguments[d]);for(d=0;d<c.length;d++)this.attributes.hasOwnProperty(c[d])&&(e[c[d]]=this.get(c[d]));return e};a.b.g("Model.prototype.pick",{kja:a.C.prototype.kja});a.C.prototype.Pha=function(){var a,c={},d;for(a in this.attributes)this.attributes.hasOwnProperty(a)&&(d=this.get(a),c[d]=a);return c};a.b.g("Model.prototype.invert",{Pha:a.C.prototype.Pha});a.C.gva=function(a){return a.charAt(a.length-1)};
a.C.prototype.kDa=function(){var a=this.h9();return a?a:this.uB()?this.uB().url:null};a.C.prototype.h9=function(){return a.C.Sr(this,"urlRoot")};a.C.prototype.parseSave=function(a){return a};a.C.prototype.isValid=function(){var a={};a.validate=this.validate;return this.CC(this.attributes,a,!1)};a.b.g("Model.prototype.isValid",{isValid:a.C.prototype.isValid});a.C.Jza=function(a,c){a=a||{};return void 0!==a.validate&&null!==a.validate?a.validate:c};a.C.prototype.CC=function(b,c,d){c=c||{};var e=this.validate;
return e&&a.C.Jza(c,d)&&(this.validationError=e.call(this,b,c))?(this.Kc(!1,a.ka.O.INVALID,this,this.validationError,c),!1):!0};a.C.xBa=function(b){var c=!1,d={},e,f={};if(b&&0<b.length){1<b.length&&b[b.length-1]&&a.C.eK(b[b.length-1])&&(c=!0,d=b[b.length-1]||{});if(null==b[0])return{attributes:null,options:d};if(a.C.eK(b[0])||a.b.vi(b[0]))for(e in b[0])b[0].hasOwnProperty(e)&&(f[e]=b[0][e]);else for(e=0;e<b.length;e+=2)if(void 0!==b[e]||e<b.length-1||!c&&e===b.length-1)f[b[e]]=b[e+1]}return{attributes:f,
options:d}};a.C.iv=function(a){var c={},d;a=a||{};for(d in a)a.hasOwnProperty(d)&&(c[d]=a[d]);return c};a.C.YE=function(b,c,d,e,f,h){d=d||{};d.textStatus=e;d.errorThrown=f;b.Kc(c,a.ka.O.ERROR,b,h,d)};a.C.prototype.save=function(b,c){var d,e,f,h,k,l;d=a.C.xBa(arguments);var m,r,t;t=void 0===b?void 0:d.attributes;c=c||{};m=a.C.iv(d.options);d=g.extend(!0,{},this.attributes,t);if(!this.CC(d,m,!0))return!1;m.wait||this.set(t);d=void 0===m.forceNew?!1:m.forceNew;h=this;k=m.error;l=m.patch;m.error=function(b,
d,e){a.C.YE(h,!1,c,d,e,b);k&&k.apply(h,arguments)};m.saveAttrs=m.wait?this.hqa(t):this.attributes;r=this.attributes;this.attributes=m.saveAttrs;m.saveAttrs=this.toJSON();this.attributes=r;if(!d&&!this.oN())return e=m.success,m.success=function(b){var d;m.xhr&&(c.xhr=m.xhr);if(b&&!a.b.vi(b)){d=g.isFunction(h.parse)?h.parse(b):b;h.attributes=g.extend(!0,h.attributes,d);if(m.wait)for(var k in t)d.hasOwnProperty(k)&&(t[k]=d[k]);h.io()}a.C.fJ(h,b,m);m.wait&&h.set(t);e&&e.call(a.C.vl(m,h),h,b,c);h.uy()},
m.attrs||(m.attrs=void 0===t?void 0:l?t:m.saveAttrs),a.C.GD(l?"patch":"update",this,m);f=a.C.V8(m);m.success=function(b){var d;m.xhr&&(c.xhr=m.xhr);if(b&&!a.b.vi(b)){d=g.isFunction(h.parse)?h.parse(b):b;if(!h.CC(d,m,!0))return;h.attributes=g.extend(!0,h.attributes,d);if(m.wait)for(var e in t)d.hasOwnProperty(e)&&(t[e]=d[e]);h.io()}a.C.fJ(h,b,m);m.wait&&h.set(t);f&&f.call(a.C.vl(m,h),h,b,c);h.uy()};m.attrs||(m.attrs=m.saveAttrs);m.parse=!0;l&&(m.saveAttrs=m.attrs);return a.C.GD("create",this,m)};a.b.g("Model.prototype.save",
{save:a.C.prototype.save});a.C.prototype.hqa=function(a){var c={},d;for(d in this.attributes)this.attributes.hasOwnProperty(d)&&(c[d]=this.attributes[d]);for(d in a)a.hasOwnProperty(d)&&(c[d]=a[d]);return c};a.C.Sr=function(a,c){return a?g.isFunction(a[c])?a[c]():a[c]:g.isFunction(c)?c():c};a.C.A0=function(a){return a&&a.hasOwnProperty("value")&&a.hasOwnProperty("comparator")};a.C.prototype.nya=function(b){for(var c in b)if(b.hasOwnProperty(c)){if(!this.attributes.hasOwnProperty(c))return!1;for(var d=
Array.isArray(b[c])?b[c]:[b[c]],e=0;e<d.length;e++)if(a.C.A0(d[e])){var f=d[e].comparator,h=d[e].value;if(a.cb.Re(f))throw Error("String comparator invalid for local where/findWhere");if(!f(this,c,h))return!1}else if(b[c]!==this.attributes[c])return!1}return!0};a.C.prototype.matches=function(a){a:{for(var c in a)if(this.get(c)!==a[c]){a=!1;break a}a=!0}return a};a.b.g("Model.prototype.matches",{matches:a.C.prototype.matches});a.C.prototype.ala=function(a){a=a.constructor===Array?a:[a];var c;for(c=
0;c<a.length;c++)if(this.nya(a[c]))return!0;return!1};a.C.V8=function(a){return null!=a&&a.success?a.success:null};a.C.vl=function(a,c){return void 0!==a&&void 0!==a.context?a.context:c};a.C.prototype.oN=function(){return void 0==this.Mi()};a.b.g("Model.prototype.isNew",{oN:a.C.prototype.oN});a.C.prototype.wT=function(){return this.idAttribute||"id"};a.C.prototype.Mi=function(){return this.id};a.C.prototype.eY=function(b){if(b){var c={},d;for(d in b)b.hasOwnProperty(d)&&(a.b.kC(b[d],this.attributes[d])||
(c[d]=b[d]));return a.b.vi(c)?!1:c}return a.b.vi(this.changed)?!1:this.changed};a.b.g("Model.prototype.changedAttributes",{eY:a.C.prototype.eY});a.C.prototype.kZ=function(b){return void 0!==b?a.C.eK(this.changed)&&this.changed.hasOwnProperty(b):a.C.eK(this.changed)};a.b.g("Model.prototype.hasChanged",{kZ:a.C.prototype.kZ});a.C.prototype.destroy=function(b){b=b||{};var c=b.wait,d,e=b.error,f=this,h,k;k=a.C.iv(b);d=a.C.V8(k);var g=this.uB();k.success=function(e){k.xhr&&(b.xhr=k.xhr);if(g){var h=a.cb.Re(e)&&
!a.cb.vi(e)?JSON.parse(e):e;g.ida(h,null,e,!0)}c&&f.ZS();a.C.fJ(f,e,k);d&&d.call(a.C.vl(k,f),f,e,b)};k.error=function(c,d,h){f.Kc(!1,a.ka.O.ERROR,f,c,b);e&&e.apply(f,arguments)};if(!this.oN())return h=a.C.GD("delete",this,k),c||this.ZS(),h;c||this.ZS();d&&d.call(a.C.vl(k,f),f,null,b);return!1};a.b.g("Model.prototype.destroy",{destroy:a.C.prototype.destroy});a.C.prototype.i7=function(b,c,d,e){this.Kc(e,a.ka.O.REQUEST,b,c,d)};a.C.prototype.ZS=function(){this.Kc(!1,a.ka.O.DESTROY,this,this.collection,
null)};a.C.fJ=function(b,c,d){b.Kc(!1,a.ka.O.SYNC,b,c,d)};a.C.prototype.toJSON=function(){var a={},c;for(c in this.attributes)this.attributes.hasOwnProperty(c)&&(Array.isArray(this.attributes[c])?a[c]=this.attributes[c].slice(0):a[c]=this.attributes[c]);return a};a.b.g("Model.prototype.toJSON",{toJSON:a.C.prototype.toJSON});a.C.prototype.oG=function(a){return this.m_[a]};a.b.g("Model.prototype.previous",{oG:a.C.prototype.oG});a.C.prototype.qja=function(){return this.m_};a.b.g("Model.prototype.previousAttributes",
{qja:a.C.prototype.qja});a.C.prototype.Nr=function(b,c,d){return a.sync(b,c,d)};a.b.g("Model.prototype.sync",{Nr:a.C.prototype.Nr});a.C.GD=function(b,c,d){d=d||{};c.oauth&&(d.oauthHeader=c.oauth.getHeader());!d.dataType&&c.dataType&&(d.dataType=c.dataType);!d.jsonpCallback&&c.jsonpCallback&&(d.jsonpCallback=c.jsonpCallback);if("create"===b||"patch"===b||"update"===b)d.j_=c.parseSave.call(c,"patch"===b?d.attrs:d.saveAttrs);var e=null;c instanceof a.C&&(e=c.Mi());var f={};if(d)for(var h in d)f[h]=d[h];
e=a.C.e1(e,c,d);for(h in e)f[h]=e[h];d.xhr=c.sync(b,c,f);f.xhr&&(d.xhr=f.xhr);return d.xhr};a.C.e1=function(b,c,d){c=c instanceof a.l?c.Kla(d):{};b&&(c.recordID=b);return c};a.Nr=function(b,c,d){function e(a){c.i7(c,a,d,d.silent);return a}d=d||{};var f,h=d.success,k=d.error;f=c.customURL;if("create"===b.valueOf())return b=(b=c.kDa())?b:a.C.Sr(c,"url"),f=new a.Eb(b,f),e(f.$Fa(d.j_,k,d,c));if("read"===b.valueOf()){if(c instanceof a.C)return b=d.url?d.url:a.C.Sr(c,"url"),f=new a.Eb(b,f),e(f.VY(h,k,c.Mi(),
d,a.C.vl(d,c)));b=c.s0(d);f=new a.Eb(b,f);return e(f.gIa(h,k,d,c))}f=new a.Eb(a.C.Sr(c,"url"),f);var g=null;c instanceof a.C&&(g=c.Mi());return"update"===b.valueOf()?e(f.Hka(h,g,d.j_,k,d,c,!1)):"patch"===b.valueOf()?e(f.Hka(h,g,d.j_,k,d,c,!0)):"delete"===b.valueOf()?e(f.rHa(g,k,d,c)):null};o_("sync",a.Nr,a);a.C.PFa=function(a){if(!a.url)throw Error("The url property or function must be specified");};a.ajax=function(b){arguments&&0<arguments.length&&a.C.PFa(arguments[0]);return g.ajax.apply(a,arguments)};
o_("ajax",a.ajax,a);a.Xr=function(){this.name="URLError";this.message="No URL defined"};o_("URLError",a.Xr,a);a.Xr.prototype=Error();a.Xr.constructor=a.Xr;a.Eb=function(a,c){this.tG=a;this.En=c;g.support.cors=!0};a.Eb.$x="headers";a.Eb.hF=function(b,c,d){var e;b=g.extend(!0,b,d);for(e in c)c.hasOwnProperty(e)&&"oauthHeader"!==e&&(b.hasOwnProperty(e)||(b[e]=c[e]),e===a.Eb.$x&&(b[e]=g.extend(!0,b[e],c[e])));if(c.oauthHeader)for(e in b[a.Eb.$x]||(b[a.Eb.$x]={}),c.oauthHeader)c.oauthHeader.hasOwnProperty(e)&&
(b[a.Eb.$x].hasOwnProperty(e)||(b[a.Eb.$x][e]=c.oauthHeader[e]));return b};a.Eb.prototype.gIa=function(b,c,d,e){d=d||{};var f="jsonp"===d.dataType,h=this.wD("read",this.tG,this.En,null,e,d);b={crossDomain:d.crossDomain||!f,dataType:this.sJ(d),jsonpCallback:d.jsonpCallback,context:null!==e?e:this,success:b,error:c};b=this.dI(b);b=a.Eb.hF(b,d,h);d.xhr=this.ajax(b,e);return d.xhr};a.Eb.prototype.dI=function(b){b[a.Eb.$x]={"Accept-Language":this.hj()};return b};a.Eb.prototype.VY=function(b,c,d,e,f){e=
e||{};var h="jsonp"===e.dataType;d=this.wD("read",this.tG,this.En,d,f,e);b={crossDomain:e.crossDomain||!h,dataType:this.sJ(e),jsonpCallback:e.jsonpCallback,context:null!==f?f:this,success:b,error:c};b=this.dI(b);b=a.Eb.hF(b,e,d);e.xhr=this.ajax(b,f);return e.xhr};a.Eb.prototype.Hka=function(b,c,d,e,f,h,k){f=f||{};var g="jsonp"===f.dataType;c=this.wD(k?"patch":"update",this.tG,this.En,c,h,f);k=a.Eb.Gy(f);b={crossDomain:f.crossDomain||!g,contentType:this.Fua(f),dataType:this.sJ(f),jsonpCallback:f.jsonpCallback,
data:this.Ob(JSON.stringify(d),f,c),emulateHTTP:k,emulateJSON:a.Eb.Hy(f),success:b,error:e,context:null!==h?h:this};b=this.dI(b);b=a.Eb.hF(b,f,c);b=a.Eb.B4(k,b);f.xhr=this.ajax(b,h);return f.xhr};a.Eb.B4=function(a,c){if(a){var d=c.beforeSend;c.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",c.Wl);if(d)return d.apply(this,arguments)}}return c};a.Eb.prototype.Ob=function(b,c,d){return a.Eb.Hy(c)?(c={_method:d.Wl?d.Wl:d.type},b&&(c.model=b),c):b};a.Eb.prototype.Yua=function(b,c){if(c.type)return{method:c.type};
var d=null;"create"===b&&(d="POST");"delete"===b&&(d="DELETE");"patch"===b&&(d="PATCH");"update"===b&&(d="PUT");if(a.Eb.Gy(c)){var e={method:"POST"};e.Wl=d;return e}null===d&&(d="GET");return{method:d}};a.Eb.Gy=function(b){return b.emulateHTTP||a.emulateHTTP};a.Eb.Hy=function(b){return b.emulateJSON||a.emulateJSON};a.Eb.prototype.wD=function(b,c,d,e,f,h){var k=this.Yua(b,h);if(g.isFunction(d)){b=d.call(this,b,f,a.C.e1(e,f,h));if(a.cb.Re(b))return c={url:b,type:k.method},k.Wl&&(c.Wl=k.Wl),c;if(b)return b.url=
b.hasOwnProperty("url")?b.url:c,b.hasOwnProperty("type")||(b.type=k.method),!b.hasOwnProperty("data")&&k.Wl&&(b.Wl=k.Wl),b}c={url:a.C.Sr(null,c),type:k.method};k.Wl&&(c.Wl=k.Wl);return c};a.Eb.prototype.rHa=function(b,c,d,e){d=d||{};var f="jsonp"===d.dataType;b=this.wD("delete",this.tG,this.En,b,e,d);var h=a.Eb.Gy(d);c={crossDomain:d.crossDomain||!f,success:d.success,error:c,context:null!==e?e:this,emulateHTTP:h,emulateJSON:a.Eb.Hy(d)};(f=this.Ob(null,d,b))&&(c.data=f);c=a.Eb.hF(c,d,b);c=a.Eb.B4(h,
c);d.xhr=this.ajax(c,e);return d.xhr};a.Eb.prototype.$Fa=function(b,c,d,e){d=d||{};var f=JSON.stringify(b),h="jsonp"===d.dataType;b=this.wD("create",this.tG,this.En,null,e,d);var k=a.Eb.Gy(d);c={crossDomain:d.crossDomain||!h,contentType:d.contentType||"application/json",dataType:this.sJ(d),jsonpCallback:d.jsonpCallback,data:this.Ob(f,d,b),success:d.success,error:c,emulateHTTP:k,emulateJSON:a.Eb.Hy(d),context:null!==e?e:this};c=this.dI(c);c=a.Eb.hF(c,d,b);d.xhr=this.ajax(c,e);return d.xhr};a.Eb.prototype.sJ=
function(b){return a.Eb.Hy(b)&&!a.Eb.Gy(b)?"application/x-www-form-urlencoded":b.dataType||"json"};a.Eb.prototype.Fua=function(b){return a.Eb.Hy(b)&&!a.Eb.Gy(b)?"application/x-www-form-urlencoded":b.contentType||"application/json"};a.Eb.prototype.hj=function(){return a.fa.hj()};a.Eb.prototype.ajax=function(b,c){if(null===b.url||void 0===b.url)throw new a.Xr;var d=a.ajax(b);c.d4&&c.d4(d);return d};a.Dc=function(b,c){c=c||{};a.Dc._init(this,c,b||"Authorization")};o_("OAuth",a.Dc,a);a.b.sa(a.Dc,a.b,
"oj.OAuth");a.Dc.prototype.Init=function(){a.Dc.u.Init.call(this)};a.Dc.prototype.uga=function(){var a={};this.st.access_token||this.gY();a[this.jp.Zea]="Bearer "+this.st.access_token;return a};a.b.g("OAuth.prototype.getHeader",{uga:a.Dc.prototype.uga});a.Dc.prototype.Sha=function(){return this.st.ANa?!0:!1};a.b.g("OAuth.prototype.isInitialized",{Sha:a.Dc.prototype.Sha});a.Dc.prototype.gY=function(){var b={},c=this;b[c.jp.Zea]="Basic "+a.Dc.oqa(c.jp.client_id+":"+c.jp.client_secret);g.ajax({type:"POST",
async:!1,url:this.jp.bearer_url,data:"grant_type\x3dclient_credentials",headers:b,success:function(b){a.Dc.FD(c.st,b)},error:function(a){throw Error(a.responseText);}})};a.b.g("OAuth.prototype.clientCredentialGrant",{gY:a.Dc.prototype.gY});a.Dc.prototype.Pja=function(b){a.Dc.FD(this.st,b)};a.b.g("OAuth.prototype.setAccessTokenResponse",{Pja:a.Dc.prototype.Pja});a.Dc.prototype.$fa=function(){return this.st};a.b.g("OAuth.prototype.getAccessTokenResponse",{$fa:a.Dc.prototype.$fa});a.Dc.prototype.ifa=
function(){a.Dc.g5(this.st)};a.b.g("OAuth.prototype.cleanAccessTokenResponse",{ifa:a.Dc.prototype.ifa});a.Dc.prototype.Oja=function(b){a.Dc.FD(this.jp,b)};a.b.g("OAuth.prototype.setAccessTokenRequest",{Oja:a.Dc.prototype.Oja});a.Dc.prototype.Zfa=function(){return this.jp};a.b.g("OAuth.prototype.getAccessTokenRequest",{Zfa:a.Dc.prototype.Zfa});a.Dc.prototype.hfa=function(){a.Dc.g5(this.jp)};a.b.g("OAuth.prototype.cleanAccessTokenRequest",{hfa:a.Dc.prototype.hfa});a.Dc._init=function(b,c,d){b.Init();
b.jp={};b.st={};c.access_token?a.Dc.FD(b.st,c):c.client_id&&c.client_secret&&c.bearer_url&&a.Dc.FD(b.jp,c);b.jp.Zea=d};a.Dc.FD=function(a,c){var d;c=c||{};for(d in c)a[d]=c[d]};a.Dc.g5=function(a){for(var c in a)a.hasOwnProperty(c)&&"auth_header"!==c&&(a[c]=null,delete a[c])};a.Dc.oqa=function(a){var c,d,e,f,h=0,k=0,g=[];do c=a.charCodeAt(h++),d=a.charCodeAt(h++),e=a.charCodeAt(h++),f=c<<16|d<<8|e,c=f>>18&63,d=f>>12&63,e=f>>6&63,f&=63,g[k++]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d".charAt(c)+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d".charAt(d)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d".charAt(e)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\x3d".charAt(f);while(h<a.length);g=g.join("");c=a.length%3;return(c?g.slice(0,c-3):g)+"\x3d\x3d\x3d".slice(c||3)};a.l=function(b,c){a.l.UD||a.l._init(this,b,c,null)};o_("Collection",a.l,a);a.b.sa(a.l,a.b,"oj.Collection");a.l.prototype.Zt=null;a.b.g("Collection.prototype.model",
{Zt:a.l.prototype.Zt});a.l.prototype.Oia=function(a){var c=this.model;return c&&a?a[c.idAttribute||c.prototype.idAttribute||"id"]:null};a.b.g("Collection.prototype.modelId",{Oia:a.l.prototype.Oia});a.l.prototype.length=void 0;a.b.g("Collection.prototype.length",{length:a.l.prototype.length});a.l.prototype.Qia=void 0;a.b.g("Collection.prototype.models",{Qia:a.l.prototype.Qia});a.l.prototype.cd=[];a.l.prototype.url=null;a.b.g("Collection.prototype.url",{url:a.l.prototype.url});a.l.prototype.wt=[];a.b.g("Collection.prototype.changes",
{wt:a.l.prototype.wt});a.l.prototype.En=null;a.b.g("Collection.prototype.customURL",{En:a.l.prototype.En});a.l.prototype.Efa=null;a.b.g("Collection.prototype.customPagingOptions",{Efa:a.l.prototype.Efa});a.l.prototype.cia=void 0;a.b.g("Collection.prototype.lastFetchSize",{cia:a.l.prototype.cia});a.l.prototype.zha=!1;a.b.g("Collection.prototype.hasMore",{zha:a.l.prototype.zha});a.l.prototype.uka=void 0;a.b.g("Collection.prototype.totalResults",{uka:a.l.prototype.uka});a.l.prototype.bia=void 0;a.b.g("Collection.prototype.lastFetchCount",
{bia:a.l.prototype.bia});a.l.prototype.Pia=-1;a.b.g("Collection.prototype.modelLimit",{Pia:a.l.prototype.Pia});a.l.prototype.offset=void 0;a.b.g("Collection.prototype.offset",{offset:a.l.prototype.offset});a.l.prototype.Pfa=-1;a.b.g("Collection.prototype.fetchSize",{Pfa:a.l.prototype.Pfa});a.l.prototype.G_=1;a.b.g("Collection.prototype.sortDirection",{G_:a.l.prototype.G_});a.l.prototype.bm=null;a.b.g("Collection.prototype.comparator",{bm:a.l.prototype.bm});a.l.prototype.Init=function(){a.l.u.Init.call(this)};
a.l.extend=function(b,c){a.l.UD=!0;var d=new a.l;a.l.UD=!1;g.extend(d,this.prototype);var e;e=b&&b.constructor&&b.hasOwnProperty("constructor")?b.constructor:function(c,d){a.l._init(this,c,d,b)};if(c)for(var f in c)c.hasOwnProperty(f)&&(e[f]=c[f]);if(b)for(f in b)b.hasOwnProperty(f)&&(d[f]=b[f]);g.extend(e,this);e.prototype=d;e.extend=a.l.extend;return e.prototype.constructor=e};o_("Collection.extend",a.l.extend,a);a.l._init=function(b,c,d,e){var f,h;b.Init();a.ka.jP(b);if(e)for(f in e)e.hasOwnProperty(f)&&
(b[f]=e[f]);d=d||{};h=["comparator","customPagingOptions","customURL",a.l.If,"model","modelLimit","sortDirection","url"];for(f=0;f<h.length;f++)d.hasOwnProperty(h[f])&&void 0!==d[h[f]]&&(b[h[f]]=d[h[f]]);void 0===b.Go(null)&&b.mO(-1);void 0===b.modelLimit&&b.z_(-1);b.hasMore=!1;b.im=0;b.mw([],!0);d.parse&&(c=b.parse(c));if(null!=c)for(d.Yia=!0,h=c instanceof Array?c:[c],f=0;f<h.length;f+=1)b.add(h[f],d);b.bp();c||(b.totalResults=void 0);e&&e.initialize&&e.initialize.call(b,c,d)};a.l.prototype.on=
function(){};a.l.prototype.Zp=function(){};a.l.prototype.Kc=function(){};a.l.prototype.i7=function(b,c,d,e){this.Kc(e,a.ka.O.REQUEST,b,c,d)};a.l.prototype.SCa=function(){this.changes=[]};a.l.prototype.AW=function(a,c){for(var d=a;d<a+c;d++)-1===this.changes.indexOf(d)&&(this.changes.push(d),this.changes.sort(function(a,b){return a-b}))};a.l.prototype.mw=function(a,c){this.models=a;if(c)this.cd=[],this.SCa();else for(var d=0;d<a.length;d++)a[d]&&this.cd.push(d)};a.l.prototype.Xd=function(){return this.models};
a.l.prototype.Ke=function(){return this.Xd().length};a.l.prototype.cBa=function(a){return a<this.Ke()||this.Ib()&&(!this.Rs()||0===this.Ke())?!1:!0};a.l.prototype.Rs=function(){return a.l.wq(this.totalResults)};a.l.wq=function(a){return null!=a};a.l.prototype.HBa=function(a){this.Xd().push(a);this.cd.push(this.Ke()-1);this.AW(this.Ke()-1,1)};a.l.prototype.IBa=function(a){this.wV(a);this.HBa(a);this.im++;a.IB(this.Ke()-1)};a.l.prototype.Dba=function(a){if(a)for(var c=0;c<a.length;c++)a[c]&&this.im--};
a.l.prototype.Qda=function(a,c,d){for(var e=a;e<a+c;e++)this.gca(this.Rc(e));void 0===d?(this.Dba(this.Xd().splice(a,c)),this.Pda(a,a+c-1)):(this.Dba(this.Xd().splice(a,c,d)),this.Pda(a,a+c-1),this.eza(a),this.wV(d));this.AW(a,c);0>this.im&&(this.im=0);this.Cba(a)};a.l.prototype.Rc=function(a){return this.Xd()[a]};a.l.prototype.Cba=function(a){for(var c,d=0;d<this.cd.length;d++)c=this.cd[d],c>=a&&this.Rc(c)&&this.Rc(c).IB(c)};a.l.prototype.gca=function(a){if(a){var c=a.n_;a=a.pKa;c?c.vP(a):this.head=
a;a?a.aH(c):this.tail=c}};a.l.prototype.wV=function(a){a.vP(this.head);this.head?this.head.aH(a):this.tail=a;a.aH(null);this.head=a};a.l.prototype.ZDa=function(a){-1===this.cd.indexOf(a)&&this.cd.push(a)};a.l.prototype.eza=function(a){for(var c=0;c<this.cd.length;c++)this.cd[c]>=a&&this.cd[c]++;this.cd.push(a)};a.l.prototype.Pda=function(a,c){void 0===c&&(c=a);this.r5(a,c);for(var d=c-a+1,e=0;e<this.cd.length;e++)this.cd[e]>c&&(this.cd[e]-=d)};a.l.prototype.r5=function(a,c){void 0===c&&(c=a);for(var d=
a;d<=c;d++){var e=this.cd.indexOf(a);-1<e&&this.cd.splice(e,1)}};a.l.prototype.vL=function(a,c){var d=this.Rc(a);this.gca(d);d||this.im++;this.AW(a,1);if(this.Xd()[a]=c)this.ZDa(a),c.IB(a),this.wV(c)};a.l.prototype.gra=function(a){var c=this.tail,d,e,f=0;for(this.tail=null;c&&f<a;)d=c.pla(),(e=this.Rc(d))&&e.kZ()?(this.tail||(this.tail=c),c=c.n_):(this.im--,-1<d&&(this.vL(d,void 0),this.r5(d,d)),c.vP(null),c=c.aH(null),f++);this.tail||(this.tail=c);0>this.im&&(this.im=0);0===this.im&&(this.tail=this.head=
null)};a.l.prototype.DE=function(){this.im=0;this.tail=this.head=null};a.l.prototype.Wv=function(a){if(this.Ib()){var c=this.u8();-1<c&&this.im+a>c&&this.gra(this.im+a-c)}};a.l.prototype.clone=function(){return this.u5(!0)};a.b.g("Collection.prototype.clone",{clone:a.l.prototype.clone});a.l.prototype.u5=function(a){var c=new this.constructor,d;this.Ib()&&(c=this.Ira(c),c.sW());c=this.Jra(c);if(a){var e=[];for(a=0;a<this.cd.length;a++)e.push(this.cd[a]);e.sort(function(a,b){return a-b});var f;for(a=
0;a<e.length;a++)f=e[a],(d=this.pq(f,null,!0,!1))&&c.nq(d.clone(),{at:f},!0,!1)}return c};a.l.prototype.Jra=function(a){var c=["comparator","model","modelId"],d,e;for(e=0;e<c.length;e++)d=c[e],a[d]=this[d];return a};a.l.prototype.Ira=function(b){var c=["totalResults","hasMore",a.l.If],d,e;for(e=0;e<c.length;e++)d=c[e],b[d]=this[d];return b};a.l.prototype.vf=function(){return this.length};a.l.prototype.bp=function(){var a=this.Ke();this.length=a;this.Ib()||(this.totalResults=a)};a.l.jS=function(a,
c,d){return a.model?g.isFunction(a.model)?new a.model(c,d):new a.model.constructor(c,d):null};a.l.prototype.fE=function(b,c,d){var e=null;c=c||{};c.xJa=d;b instanceof a.C?e=b:this.model?e=a.l.jS(this,b,c):(c.collection=this,e=new a.C(b,c));return c.validate&&e.validate&&(b=e.validate(e.attributes))?(c.validationError=b,this.Kc(!1,a.ka.O.INVALID,e,b,c),null):e};a.l.prototype.add=function(a,c){this.Wv(1);return this.BD(this.nq(a,c,!1,(c||{}).deferred))};a.b.g("Collection.prototype.add",{add:a.l.prototype.add});
a.l.prototype.nq=function(b,c,d,e){function f(b,e,h,k,f){var g,l=null;!t&&n&&h?(v=h.Gla(e,b.comparator,r),l=h):(t||(g=b.j8(k))&&d&&m!==g.index&&a.t.warn("Duplicate ID fetched or added without merging, the id \x3d "+g.Mi()),void 0===g?(void 0===m?(b.IBa(k),q=b.Ke()-1,b.Rc(q).$G()):(q=m,b.Ib()&&d?b.vL(q,k):b.Qda(q,0,k),b.Rc(q).$G(),m+=1),void 0===k.uB()&&k.HB(b),b.bp(),b.Xza(k),w=!0,l=k):l=g);d&&(c=c||{},c.fillIn=!0);v&&void 0===g&&!u&&void 0===m&&1<b.vf()&&(-1<q&&(p=b.Rc(q).cid),e={},a.Uc.yf(e,c),
e.add=!0,b.sort(e),-1<q&&(q=b.Ib()?-1:b.indexOf(b.GY(p),f)));w&&(c.at&&(c.index=q),k?(k.Kc(r,a.ka.O.ADD,k,b,c),y.push(k)):(h.Kc(r,a.ka.O.ADD,h,b,c),y.push(h)));return l}function h(b,e,h){w=!1;var k=b.fE(e,c,!1),g=null,l=null;if(null!=k){q=-1;k.io();g=e instanceof a.C?e:k;if(h)return t?new Promise(function(a){var c=f(b,g,void 0,k,h);x.push(c);a(c)}):b.Rk(g,{silent:!0},h,!0).then(function(a){l=a.m;a=f(b,g,l,k,h);x.push(a)});!t&&n&&(l=d?b.j8(g):b.get(g));(e=f(b,g,l,k,h))&&x.push(e)}else x.push(!1)}function k(a,
b){return a.parse&&c.parse&&!c.Yia?a.parse(b):b}c=c||{};var g=[],m=c.at,r=c.silent,t=c.force,s,q,p,n=c.merge||!1,u=c.sort,v=!0,w=!1,y=[],x=[];void 0!==m&&0>m&&(m+=this.vf()+1);b instanceof Array?g=b:g.push(b);if(!d&&(this.Ib()||e)){var z=this;return new Promise(function(b,d){function e(a){return new Promise(function(b,c){h(z,g[a],!0).then(function(){b(a+1)},c)})}var f=Promise.resolve(0);g=k(z,g);for(s=0;s<g.length;s++)f=f.then(e);f.then(function(){0<y.length&&z.Kc(c.silent,a.ka.O.ALLADDED,z,y,c);
b(a.l.uW(x))},d)})}g=k(this,g);for(s=0;s<g.length;s++)h(this,g[s],!1);0<y.length&&this.Kc(c.silent,a.ka.O.ALLADDED,this,y,c);return a.l.uW(x)};a.l.uW=function(a){return 1===a.length?a[0]:a};a.l.prototype.S9=function(){return a.l.wq(this.comparator)};a.l.prototype.sort=function(b){b=b||{};var c=b.silent,d=this.comparator,e;if(!this.S9())return null;if(this.Ib()){var f=this.totalResults;this.Rs()?this.mw(Array(f),!0):(this.mw([],!0),this.DE(),this.bp());f=b.add?{add:!0}:null;this.Kc(c,a.ka.O.SORT,this,
f,null);c=b.startIndex;return void 0!==c&&null!==c?this.vG(c,this.Go(b)):null}e=this;this.Xd().sort(function(b,c){return a.l.n1(b,c,d,e,e)});this.Cba(0);f=b.add?{add:!0}:null;this.Kc(c,a.ka.O.SORT,this,f,null);return null};a.b.g("Collection.prototype.sort",{sort:a.l.prototype.sort});a.l.ic=function(b,c){return b instanceof a.C?b.get(c):a.C.Sr(b,c)};a.l.n1=function(b,c,d,e,f){var h,k,l;if(g.isFunction(d)){if(1===d.length){h=d.call(f,b);k=d.call(f,c);h=a.cb.Re(h)?h.split(","):[h];var m=a.cb.Re(k)?k.split(","):
[k];for(l=0;l<h.length;l++)if(k=a.l.rq(h[l],m[l],e.sortDirection),0!==k)return k}return d.call(f,b,c)}if(a.cb.Re(d))for(d=d.split(","),l=0;l<d.length;l++)if(h=a.l.ic(b,d[l]),k=a.l.ic(c,d[l]),k=a.l.rq(h,k,e.sortDirection),0!==k)return k;return 0};a.l.prototype.hka=function(b,c){var d=c?c:this.comparator,e;if(!d)return-1;this.ki("sortedIndex");e=this;return a.l.Wta(this.Xd(),b,function(b,c){var k,l;if(g.isFunction(d)){if(1===d.length){k=d.call(e,b);l=d.call(e,c);k=a.cb.Re(k)?k.split(","):[k];l=a.cb.Re(l)?
l.split(","):[l];var m,r;for(r=0;r<k.length;r++)if(m=a.l.rq(k[r],l[r],e.sortDirection),0!==m)return m}return d.call(e,b,c)}return a.cb.Re(d)?(k=b.get(d),l=c.get(d),a.l.rq(k,l,e.sortDirection)):0})};a.b.g("Collection.prototype.sortedIndex",{hka:a.l.prototype.hka});a.l.Wta=function(a,c,d){function e(f,h){var k,g;if(f>h)return-1;k=c.zu();g=c.Mi();if(a[f].Gu(g,k))return f;if(a[h].Gu(g,k))return h;k=Math.floor((h+f)/2);return-1===d(a[k],c)?e(f+1,k):1===d(a[k],c)?e(k,h-1):k}return e(0,a.length-1)};a.l.rq=
function(a,c,d){if(-1===d){if(a<c)return 1;if(c<a)return-1}else{if(a>c)return 1;if(c>a)return-1}return 0};a.l.prototype.unshift=function(b,c){var d={};a.Uc.yf(d,c||{});d.at||(d.at=0);this.Wv(1);return this.BD(this.nq(b,d,!1,d.deferred))};a.b.g("Collection.prototype.unshift",{unshift:a.l.prototype.unshift});a.l.prototype.BD=function(a){return g.isFunction(a.then)?this.$f(function(){return a}):a};a.l.prototype.shift=function(b){b=b||{};var c=this.Yh(b),d;if(this.Ib()||c){var e=this;return this.at(0,
b).then(function(c){d=e.iw(c,0,b);e.Kc(b.silent,a.ka.O.ALLREMOVED,e,[d],b);return d})}d=this.iw(this.at(0),0,b);this.Kc(b.silent,a.ka.O.ALLREMOVED,this,[d],b);return d};a.b.g("Collection.prototype.shift",{shift:a.l.prototype.shift});a.l.prototype.iN=function(a){void 0===a&&(a=1);this.ki("initial");var c=[],d;for(d=0;d<this.vf()-a;d+=1)c.push(this.at(d));return c};a.b.g("Collection.prototype.initial",{iN:a.l.prototype.iN});a.l.prototype.Yh=function(a){return(a||{}).deferred};a.l.prototype.last=function(a,
c){var d=this.Yh(c);void 0===a&&(a=1);if(1===a){var e=this.Ke();0===e&&(e=a);return 0<e?this.at(e-1,d):null}var f=[],e=this.vf();if(d||this.Ib()){var h=e-a;0>h&&(h=0);0===e&&(e=a);var k=this;return this.$f(function(){return k.Fx(h,e)})}for(d=e-a;d<e;d+=1)f.push(this.at(d));return f};a.b.g("Collection.prototype.last",{last:a.l.prototype.last});a.l.prototype.Fx=function(a,c){var d=[],e,f=this;return new Promise(function(h,k){function g(a){return f.Ib()&&f.Rs()&&a>=f.totalResults?Promise.resolve(a+1):
new Promise(function(b,c){f.uS(a,null).then(function(c){d.push(c);b(a+1)},c)})}var m=Promise.resolve(a);for(e=a;e<c;e++)m=m.then(g);m.then(function(){h(d)},k)})};a.l.prototype.K7=function(b){return void 0===b||null===b?this[a.l.If]:b};a.l.prototype.Mqa=function(){var b=this.lastFetchCount;if(void 0===b||null===b)b=this[a.l.If];return void 0===this.offset||null===this.offset?b:this.offset+b};a.l.prototype.next=function(b,c){c=c||{};c[a.l.If]=this.K7(b);var d=this.Mqa(),e=this.vf();if(0===e&&0<c[a.l.If])d=
0;else if(d>=e)return c.success&&c.success.call(a.C.vl(c,this),this,null,c),null;c.startIndex=d;return this.fetch(c)};a.b.g("Collection.prototype.next",{next:a.l.prototype.next});a.l.prototype.Nqa=function(a){return void 0===this.offset||null===this.offset?0:this.offset-a};a.l.prototype.oG=function(b,c){c=c||{};if(0===this.offset)return c.success&&this.lastFetchCount&&c.success.call(a.C.vl(c,this),this,null,c),null;c[a.l.If]=this.K7(b);var d=this.Nqa(c[a.l.If]);0>d&&(c[a.l.If]=this.offset,d=0);c.startIndex=
d;return this.fetch(c)};a.b.g("Collection.prototype.previous",{oG:a.l.prototype.oG});a.l.prototype.z_=function(a){this.modelLimit=a;this.Wv(0)};a.b.g("Collection.prototype.setModelLimit",{z_:a.l.prototype.z_});a.l.prototype.u8=function(){return this.modelLimit};a.l.prototype.mO=function(b){this[a.l.If]=b};a.b.g("Collection.prototype.setFetchSize",{mO:a.l.prototype.mO});a.l.prototype.Jja=function(a,c){var d=this.Yh(c);void 0===a&&(a=1);var e=[];if(this.Ib()||d){var f=this;return this.$f(function(){return f.Fx(a,
f.vf())})}for(d=a;d<this.vf();d+=1)e.push(this.at(d));return e};a.b.g("Collection.prototype.rest",{Jja:a.l.prototype.Jja});a.l.prototype.remove=function(b,c){c=c||{};var d=[],e;b instanceof Array?d=b:d.push(b);var f=[];for(e=d.length-1;0<=e;e-=1)f.unshift(this.iw(d[e],-1,c));this.Kc(c.silent,a.ka.O.ALLREMOVED,this,d,c);return a.l.uW(f)};a.b.g("Collection.prototype.remove",{remove:a.l.prototype.remove});a.l.prototype.iw=function(b,c,d){d=d||{};b=-1==c?this.Rk(b):a.l.Cq(c,b);var e=d.silent;c=b.index;
if(-1<c){var f=b.m;void 0!==f&&f.uB()===this&&f.HB(null);this.Qda(c,1);this.bp();var h={};a.Uc.yf(h,d);h.index=c;void 0!==f&&f.Kc(e,a.ka.O.REMOVE,f,this,h);this.vea(f)}return b.m};a.l.prototype.vea=function(a){void 0!==a&&a.off(null,null,this)};a.l.prototype.Xza=function(b){b.Zp(a.ka.O.ALL,this.uAa,this,!1,!0)};a.l.prototype.uAa=function(b,c,d,e){b===a.ka.O.DESTROY&&this.remove(c);void 0!==d&&d instanceof a.l&&d!==this||(Array.prototype.slice.call(arguments),this.Kc(e&&e.silent,b,c,d,e))};a.l.prototype.refresh=
function(b){b=b||{};var c=this;return this.$f(function(){return new Promise(function(d,e){if(!c.Ib()){var f=void 0!==b.silent&&b.silent;try{c.reset(null,{silent:!0});var h={},k;for(k in b)b.hasOwnProperty(k)&&(h[k]=b[k]);h.success=function(b,e,h){c.Kc(f,a.ka.O.REFRESH,c,h,null);d({collection:b,response:e,options:h})};h.error=function(d,h,k){e(a.l.NC(d,h,k,c,b,!1))};c.fetch(h);return}catch(g){if(g instanceof a.Xr){c.Kc(f,a.ka.O.REFRESH,c,b,null);d({collection:c,options:b});return}throw g;}}h=b.startIndex;
c.mw([],!0);c.DE();c.totalResults=void 0;c.bp();f=void 0!==b.silent&&b.silent;c.Kc(f,a.ka.O.REFRESH,c,b,null);if(void 0===h||null===h)h=0;void 0!==h&&null!==h?c.nda(h,c.Go(b)).then(function(a){d(a)},function(a){e(a)}):d(void 0)})})};a.b.g("Collection.prototype.refresh",{refresh:a.l.prototype.refresh});a.l.prototype.reset=function(b,c){var d={};a.Uc.yf(d,c||{});d.previousModels=this.Xd();for(var e,f=0;f<this.cd.length;f++)if(e=this.cd[f],e=this.Rc(e))this.vea(e),e.HB(null);this.mw([],!0);this.DE();
f=void 0!==d.silent&&d.silent;if(!b)return this.bp(),this.totalResults=void 0,this.Kc(f,a.ka.O.RESET,this,d,null),null;e=null;d.parse&&(b=this.parse(b));this.Wv(b instanceof Array?b.length:1);d.Yia=!0;e=this.nq(b,d,!0,!1);this.bp();this.Kc(f,a.ka.O.RESET,this,d,null);return this.BD(e)};a.b.g("Collection.prototype.reset",{reset:a.l.prototype.reset});a.l.prototype.at=function(a,c){return this.pq(a,c,!1,this.Yh(c))};a.b.g("Collection.prototype.at",{at:a.l.prototype.at});a.l.prototype.pq=function(a,c,
d,e){0>a&&(a+=this.vf());if(0>a||this.cBa(a))return d||!this.Ib()&&!e?null:this.$f(function(){return Promise.resolve(null)});var f=this;return d||!this.Ib()&&!e?this.Rc(a):this.$f(function(){return f.uS(a,c)})};a.l.prototype.whenReady=function(){return this.dt?this.dt:Promise.resolve()};a.b.g("Collection.prototype.whenReady",{whenReady:a.l.prototype.whenReady});a.l.prototype.$f=function(b){var c=this;void 0===this.dt&&(this.oE=0,this.dt=Promise.resolve());this.oE++;return this.dt=this.dt.then(b.bind(c)).then(function(b){c.oE--;
0===c.oE&&(c.dt=void 0,c.Kc(!1,a.ka.O.READY,c,null,null));return b},function(a){c.oE--;0===c.oE&&(c.dt=void 0);return Promise.reject(a)})};a.l.prototype.d4=function(a){if(a&&a.abort){void 0===this.ck&&(this.ck=[]);var c=this;a.done(function(){var d=c.ck?c.ck.indexOf(a):-1;-1<d&&c.ck.splice(d,1)});this.ck.push(a)}};a.l.prototype.abort=function(){var a=this;return this.ck&&0<this.ck.length?new Promise(function(c){for(var d=a.ck.length-1;0<=d;d--)a.ck[d].then(function(e,f){"abort"===f&&(a.ck.splice(d,
1),0===a.ck.length&&a.whenReady().then(function(){c(null)},function(){c(null)}))},function(){a.ck.splice(d,1);0===a.ck.length&&a.whenReady().then(function(){c(null)},function(){c(null)})}),a.ck[d].abort()}):Promise.resolve()};a.b.g("Collection.prototype.abort",{abort:a.l.prototype.abort});a.l.prototype.uS=function(b,c){var d=this,e=d.Rc(b);return void 0===e?new Promise(function(e,h){var k={};a.Uc.yf(k,c||{});k.context=d;k.startIndex=b;k.error=function(b,e,k){h(a.l.NC(b,e,k,d,c,!1))};k.success=function(){e(d.Rc(b))};
d.Gg(k,-1,!1)}):new Promise(function(a){a(e)})};a.l.prototype.GY=function(a){for(var c=this.Xd(),d,e=null,f=0;f<this.cd.length;f++)if(d=this.cd[f],c[d]&&a===c[d].cid){e=c[d];break}if(e)return e;if(this.Ib())throw Error("Not found locally and not supported by server for virtual collections");return null};a.b.g("Collection.prototype.getByCid",{GY:a.l.prototype.GY});a.l.prototype.get=function(a,c){var d=this.Rk(a,c,this.Yh(c));if(d){if(g.isFunction(d.then))return this.$f(function(){return new Promise(function(a,
b){d.then(function(b){a(b.m)},function(a){b(a)})})});if(this.Ib())return this.$f(function(){return new Promise(function(a){a(d.m)})});if(d.hasOwnProperty("m"))return d.m}return null};a.b.g("Collection.prototype.get",{get:a.l.prototype.get});a.l.prototype.j8=function(a){return(a=this.k8(a))?a.m:null};a.l.prototype.k8=function(b){var c=b;b instanceof a.C?(c=b.zu(),b=b.Mi()):a.l.wq(b)&&void 0!==b.id&&(b=b.id);for(var d=null,e=this.cd.length,f,h=this.Xd(),k,g=0;g<e;g++)if(k=this.cd[g],f=h[k],void 0!==
f&&f.Gu(b,c)){d=a.l.Cq(k,f);break}return d?d:a.l.Cq(-1,void 0)};a.l.prototype.Rk=function(b,c,d,e){var f=b;void 0===e&&(e=!1);b instanceof a.C?(f=b.zu(),b=b.Mi()):a.l.wq(b)&&void 0!==b.id&&(b=b.id);for(var h=null,k=this.Xd(),g,m=0;m<this.cd.length;m++)if(g=this.cd[m],k[g]&&k[g].Gu(b,f)){h=a.l.Cq(g,k[g]);break}if(h)return d?new Promise(function(a){a(h)}):h;if(this.Ib()){if(void 0===b&&void 0!==f)return new Promise(function(b){b(a.l.Cq(-1,void 0))});var r=this;return new Promise(function(d,h){var k=
{};a.Uc.yf(k,c||{});k.context=r;k.startID=b;k.error=function(b,d,e){h(a.l.NC(b,d,e,r,c,!1))};k.success=function(c,e){if(null!=e){var h=r.NT(),k=r.Rc(h);void 0!==k&&k.Gu(b,f)?d(a.l.Cq(h,k)):d(a.l.Cq(-1,void 0))}else d(a.l.Cq(-1,void 0))};r.Gg(k,-1,e)})}var t=a.l.Cq(-1,void 0);return d?new Promise(function(a){a(t)}):t};a.l.Cq=function(a,c){return{index:a,m:c}};a.l.prototype.parse=function(a){var c;if(a instanceof Array||!a)return a;for(c in a)if(a.hasOwnProperty(c)&&a[c]instanceof Array)return a[c];
return a};a.l.prototype.Sqa=function(a,c,d){return this.Rs()&&d.start+d.count>=this.totalResults?!0:d.start===a&&d.count===c};a.l.prototype.vG=function(a,c){var d=this;return this.$f(function(){return d.nda(a,c)})};a.b.g("Collection.prototype.setRangeLocal",{vG:a.l.prototype.vG});a.l.prototype.nda=function(a,c){this.Ib()&&this.sW();var d=this.EJ(a,c),e=this;if(this.Sqa(a,c,d))return new Promise(function(a){a(d)});var f=this.u8();-1<f&&f<c&&(this.modelLimit=c);return new Promise(function(d,k){e.mda(a,
c,-1,{start:a,count:c},d,k,!0)})};a.l.prototype.mda=function(b,c,d,e,f,h,k){var g=this,m=b+c;this[a.l.If]&&this[a.l.If]>c&&(m=this[a.l.If]+b);var r=null;this.Ib()?(r=this.S7(b,m),r>b&&(b=r,m=b+c,this[a.l.If]&&this[a.l.If]>c&&(m=this[a.l.If]+b)),r={context:this,startIndex:b,fetchSize:m-b}):r={context:this};r.error=function(b,c,d){h(a.l.NC(b,c,d,g,null,!1))};r.success=function(){var a=g.EJ(e.start,e.count);if(k&&g.Rs()&&a.count<e.count){var d=a.start+a.count,m=b+(g.lastFetchCount?g.lastFetchCount:c);
m<g.totalResults?g.mda(m,c,d,e,f,h,k):f(a)}else f(a)};try{this.Gg(r,d,-1<d)}catch(t){t instanceof a.Xr&&(d=g.EJ(b,c),f(d))}};a.l.NC=function(b,c,d,e,f,h){var k=!1;f&&f.silent&&(k=f.silent);h&&a.C.YE(e,k,f,c,d,b);f=Error(c);f.xhr=b;f.error=d;f.collection=e;f.status=c;return f};a.l.prototype.ova=function(a,c){var d=this.Ke();return 0===d?a+c:a+c>d?d:a+c};a.l.prototype.Uha=function(a,c){var d=this.EJ(a,c);return 0===this.Ke()?0===c:a===d.start&&(c===d.count||a+c>this.Ke())};a.b.g("Collection.prototype.isRangeLocal",
{Uha:a.l.prototype.Uha});a.l.prototype.tD=function(a,c){for(var d=[],e=this.Xd(),f=a+c,h=a;h<f;h++)d.push(e[h]);return d};a.l.prototype.EJ=function(a,c){if(!this.Ib()){if(0<this.Ke()){if(a+c>this.Ke()){var d=this.Ke()-a;return{start:a,count:d,models:this.tD(a,d)}}return{start:a,count:c,models:this.tD(a,c)}}return{start:a,count:0,models:[]}}d=this.ova(a,c);if(!this.Rs()&&d<a+c)return{start:a,count:d-a,models:this.tD(a,d-a)};if(0===d)return{start:a,count:0,models:[]};var e=this.S7(a,d);if(-1<e)return{start:a,
count:e-a,models:this.tD(a,e-a)};a>d?c=0:a+c>d&&(c=d-a);return{start:a,count:c,models:this.tD(a,c)}};a.l.prototype.S7=function(a,c){for(var d=a;d<c;d++)if(void 0===this.Rc(d))return d;return-1};a.l.prototype.fetch=function(a){var c=this.Gg(a,-1,!1);this.$f(function(){return Promise.resolve(c)});return c};a.b.g("Collection.prototype.fetch",{fetch:a.l.prototype.fetch});a.l.prototype.Gg=function(b,c,d){function e(a,b,c){a.Ib()?c||a.sW():b.add||b.T_||a.reset(null,{silent:!0})}var f=b||{},h=f.success,
k,g=f.error;f.set&&(f.T_=f.set?!0:!1);void 0===f.parse&&(f.parse=!0);k=this;f.error=function(c,d,e){a.C.YE(k,!1,b,d,e,c);g&&g.call(a.C.vl(b,k),c,d,e)};f.success=function(g){var l;try{l=k.parse(g,b)}catch(t){a.l.jL(k,t,f.error,b);return}k.ida(g,b,l,d);var s=null;if(f.add||k.model){e(k,f,d);try{p=!1,-1===c&&(p=!0,c=k.NT()),s=k.Tta(l,c,p,f)}catch(q){a.l.jL(k,q,f.error,b);return}}else if(!d)if(k.Ib()){e(k,f,d);var p=!1;-1===c&&(p=!0,c=k.NT());s=k.JBa(l,c,p)}else f.T_?k.GW(l,!1,f,!1):k.reset(l,{silent:!0});
k.Ib()&&s&&(k.lastFetchCount=s.length);k.Kc(f.silent?!0:!1,a.ka.O.SYNC,k,g,f);h&&h.call(a.C.vl(b,k),k,g,f)};return this.U6(f)};a.l.prototype.JBa=function(a,c,d){var e;if(a){e=a instanceof Array?a:[a];a={};d&&this.Wv(e.length);d=this.Ib();for(var f=null,h=0;h<e.length;h+=1)d&&(a={at:c},f=this.pq(c,null,!0,!1)),a.silent=!0,this.nq(e[h],a,!0,!1),this.pq(c,null,!0,!1)!==f&&c++}return e};a.l.prototype.Tta=function(b,c,d,e){e=e||{};var f=e.parse,h=a.l.jS(this);if(b){var k=b instanceof Array?b:[b];b={};
d&&this.Wv(k.length);d=this.Ib();if(e.T_&&!d){for(var g=0;g<k.length;g+=1)c=h&&f?h.parse(k[g]):k[g],k[g]=c;this.GW(k,!1,e,!1)}else{e=null;for(var m=c,g=0;g<k.length;g+=1)c=h&&f?h.parse(k[g]):k[g],d&&(b={at:m},e=this.pq(m,b,!0,!1)),b.silent=!0,this.nq(c,b,!0,!1),this.pq(m,null,!0,!1)!==e&&m++}}return k};a.l.jL=function(b,c,d,e){a.t.error(c.toString());d&&d.call(a.C.vl(e,b),b,c,e)};a.l.prototype.Pta=function(b){var c=b||{},d=c.success,e,f;void 0===c.parse&&(c.parse=!0);f=this;c.success=function(h){var k,
g,m=null,r=[];try{k=f.parse(h,b)}catch(t){a.l.jL(f,t,c.error,b);return}if(c.add||f.model)if(g=a.l.jS(f),k)for(m=k instanceof Array?k:[k],k=0;k<m.length;k+=1){if(g&&c.parse)try{e=g.parse(m[k])}catch(s){a.l.jL(f,s,c.error,b);return}else e=m[k];r.push(f.fE(e))}f.Kc(!1,a.ka.O.SYNC,f,h,c);d&&d.call(a.C.vl(b,f),f,r,c)};this.U6(c)};a.l.prototype.U6=function(b){try{return a.C.GD("read",this,b)}catch(c){throw a.C.YE(this,!1,b,null,c,null),c;}};a.l.prototype.sW=function(){var a=this.totalResults;void 0!==a&&
this.Ke()!==a&&(this.mw(Array(a),!0),this.DE(),this.bp())};a.l.prototype.Go=function(b){b=b||{};return b[a.l.If]||this[a.l.If]};a.l.prototype.Ib=function(){return-1<this.Go(null)};a.l.prototype.NJ=function(b,c,d,e,f){b=parseInt(a.l.MJ(b,c,d),10);return void 0===b||null===b||isNaN(b)?e?e:f:b};a.l.prototype.i5=function(a){return-1===a?void 0:a};a.l.prototype.ida=function(b,c,d,e){var f={};this.customPagingOptions&&((f=this.customPagingOptions.call(this,b))||(f={}));c=c||{};this.lastFetchSize=this.NJ(f,
b,"limit",c.fetchSize,this.fetchSize);this.offset=this.NJ(f,b,"offset",c.startIndex,0);this.lastFetchCount=this.NJ(f,b,"count",this.lastFetchCount,this.lastFetchCount);this.totalResults=this.i5(this.NJ(f,b,"totalResults",this.totalResults,this.totalResults));this.hasMore=this.Zua(a.l.MJ(f,b,"hasMore"),this.offset,this.lastFetchSize,this.totalResults);e||(this.totalResults=this.Npa(this.i5(parseInt(a.l.MJ(f,b,"totalResults"),10)),this.hasMore,this.offset,parseInt(a.l.MJ(f,b,"count"),10),d&&Array.isArray(d)?
d.length:0));!this.Ib()&&this.totalResults&&this.totalResults!==this.lastFetchCount&&this.lastFetchSize&&this.mO(this.lastFetchSize)};a.l.prototype.Npa=function(a,c,d,e,f){return!c&&isNaN(a)?(isNaN(e)?f:e)+d:this.totalResults};a.l.prototype.Zua=function(b,c,d,e){return a.l.wq(b)?b:void 0===e||null===e?!0:c+d>e?!1:!0};a.l.MJ=function(a,c,d){return a.hasOwnProperty(d)?a[d]:c?c[d]:void 0};a.l.prototype.NT=function(){return a.l.wq(this.offset)?this.offset:0};a.l.prototype.create=function(b,c){function d(c,
d){c.save(b instanceof a.C?null:b,d);return c}function e(a,b){if(c.wait){if(f.Ib()||h)return f.$f(function(){return Promise.resolve(void 0)})}else return f.add(a,b)}var f=this;c=c||{};var h=this.Yh(c),k=this.fE(b,c,!1),g=c.success,m=c.context;c.context=this;c.success=function(a,b,d){d.xhr&&(c.xhr=d.xhr);c.wait&&f.add(k,c);g&&g.call(null!=m?m:f,a,b,c)};if(null==k)return!1;c.forceNew=null!=k.Mi();var r=a.C.iv(c);k.HB(this);if(h||this.Ib())return new Promise(function(a){r.merge=!0;r.deferred=!0;e(k,
r).then(function(){c.success=function(b,d,e){e.xhr&&(c.xhr=e.xhr);c.wait?(f.Ib()&&(r.force=!0),f.add(k,r).then(function(){g&&g.call(null!=m?m:f,b,d,c);a(b)})):(g&&g.call(null!=m?m:f,b,d,c),a(b))};var b=d(k,c);b||a(b)})});r.merge=!0;e(k,r);return d(k,c)};a.b.g("Collection.prototype.create",{create:a.l.prototype.create});a.l.prototype.mja=function(a){var c=[],d;this.ki("pluck");for(d=0;d<this.vf();d+=1)c.push(this.at(d).get(a));return c};a.b.g("Collection.prototype.pluck",{mja:a.l.prototype.mja});a.l.prototype.Mka=
function(a,c){return this.BD(this.eF(a,c))};a.b.g("Collection.prototype.where",{Mka:a.l.prototype.Mka});a.l.prototype.eF=function(b,c){c=c||{};var d=this.Yh(c),e=this;if(this.Ib())return new Promise(function(d,h){e.Pta({query:b,all:!0,success:function(a,b){d(b)},error:function(b,d,k){h(a.l.NC(b,d,k,e,c,!0))}})});var f=[],h,k;for(h=0;h<this.vf();h+=1)k=this.at(h),k.ala(b)&&f.push(k);return d?new Promise(function(a){a(f)}):f};a.l.prototype.Nka=function(b,c){c=c||{};var d=this.Yh(c),e=this;if(this.Ib()||
d)return e.$f(function(){return new Promise(function(a,d){return e.eF(b,c).then(function(b){b=e.yaa(b);a(b)},function(a){d(a)})})});d=this.eF(b,c);d=this.yaa(d);d[a.l.If]=-1;d.bp();return d};a.b.g("Collection.prototype.whereToCollection",{Nka:a.l.prototype.Nka});a.l.prototype.yaa=function(a){var c=this.u5(!1);c.mw(a,!1);c.DE();c.bp();return c};a.l.prototype.ki=function(a){if(this.Ib())throw Error(a+" not valid on a virtual Collection");};a.l.prototype.map=function(a,c){var d=[],e;this.ki("map");this.Xd().forEach(function(f){e=
a.call(c||this,f);d.push(e)});return d};a.b.g("Collection.prototype.map",{map:a.l.prototype.map});a.l.prototype.each=function(a,c){this.ki("each");this.Xd().forEach(a,c)};a.b.g("Collection.prototype.each",{each:a.l.prototype.each});a.l.prototype.size=function(){return this.vf()};a.b.g("Collection.prototype.size",{size:a.l.prototype.size});a.l.prototype.fka=function(b,c){var d=[],e;this.ki("sortBy");this.Xd().forEach(function(a){d.push(a)});e=this;d.sort(function(d,h){var k,l;if(g.isFunction(b))return k=
b.call(c||e,d),l=b.call(c||e,h),a.l.rq(k,l,e.sortDirection);k=d.get(b);l=h.get(b);return a.l.rq(k,l,e.sortDirection)});return d};a.b.g("Collection.prototype.sortBy",{fka:a.l.prototype.fka});a.l.prototype.gha=function(a,c){var d={},e;this.ki("groupBy");this.Xd().forEach(function(f){e=g.isFunction(a)?a.call(c||this,f):f.get(a);void 0===d[e]&&(d[e]=[]);d[e].push(f)},this);return d};a.b.g("Collection.prototype.groupBy",{gha:a.l.prototype.gha});a.l.prototype.Lha=function(a,c){var d={},e;this.ki("indexBy");
this.Xd().forEach(function(f){e=g.isFunction(a)?a.call(c||this,f):f.get(a);d[e]=f},this);return d};a.b.g("Collection.prototype.indexBy",{Lha:a.l.prototype.Lha});a.l.prototype.min=function(a,c){var d={},e,f;this.ki("min");if(0==this.Ke())return null;d=this.Rc(0);e=a.call(c||this,this.Rc(0));this.Xd().forEach(function(h,k){1<=k&&(f=a.call(c||this,h),f<e&&(d=h,e=f))},this);return d};a.b.g("Collection.prototype.min",{min:a.l.prototype.min});a.l.prototype.max=function(a,c){var d={},e,f;this.ki("max");
if(0==this.Ke())return null;d=this.Rc(0);e=a.call(c,this.Rc(0));this.Xd().forEach(function(h,k){1<=k&&(f=a.call(c||this,h),f>e&&(d=h,e=f))},this);return d};a.b.g("Collection.prototype.max",{max:a.l.prototype.max});a.l.prototype.filter=function(a,c){var d=[];this.ki("filter");this.Xd().forEach(function(e){a.call(c||this,e)&&d.push(e)});return d};a.b.g("Collection.prototype.filter",{filter:a.l.prototype.filter});a.l.prototype.Oka=function(a){var c=[],d,e,f,h;this.ki("without");for(var k,g=0;g<this.Xd().length;g++){h=
!0;k=this.Rc(g);for(d=0;d<arguments.length;d+=1)if(f=arguments[d].zu(),e=arguments[d].Mi(),k.Gu(e,f)){h=!1;break}h&&c.push(k)}return c};a.b.g("Collection.prototype.without",{Oka:a.l.prototype.Oka});a.l.prototype.Hfa=function(a){var c=[],d,e,f,h,k;this.ki("difference");for(var g,m=0;m<this.Xd().length;m++){k=!0;g=this.Rc(m);for(d=0;d<arguments.length;d+=1){for(e=0;e<arguments[d].length;e++)if(h=arguments[d][e].zu(),f=arguments[d][e].Mi(),g.Gu(f,h)){k=!1;break}if(!k)break}k&&c.push(g)}return c};a.b.g("Collection.prototype.difference",
{Hfa:a.l.prototype.Hfa});a.l.prototype.vi=function(){return 0===this.vf()};a.b.g("Collection.prototype.isEmpty",{vi:a.l.prototype.vi});a.l.prototype.Rea=function(a,c){this.ki("any");for(var d,e=0;e<this.Ke();e+=1)if(d=this.Rc(e),a.call(c||this,d))return!0;return!1};a.b.g("Collection.prototype.any",{Rea:a.l.prototype.Rea});a.l.prototype.Sfa=function(a,c){var d=this.Yh(c),e=this;if(this.Ib()||d)return this.$f(function(){return new Promise(function(d){e.eF(a,c).then(function(a){a&&0<a.length&&d(a[0]);
d(null)})})});d=this.eF(a,c);return 0<d.length?d[0]:null};a.b.g("Collection.prototype.findWhere",{Sfa:a.l.prototype.Sfa});a.l.prototype.slice=function(a,c,d){var e=this.Yh(d);d=[];if(void 0===c){if(this.Ib()&&!this.Rs())throw Error("End must be set for virtual collections with no totalResults");c=this.Ke()}if(e||this.Ib()){var f=this;return this.$f(function(){return f.Fx(a,c)})}for(e=a;e<c;e+=1)d.push(this.Rc(e));return d};a.b.g("Collection.prototype.slice",{slice:a.l.prototype.slice});a.l.prototype.set=
function(a,c){return this.GW(a,!0,c,this.Yh(c)||this.Ib())};a.b.g("Collection.prototype.set",{set:a.l.prototype.set});a.l.Xba=function(a,c,d,e,f){if(d)for(d=c.length-1;0<=d;d-=1)-1==e.indexOf(d)&&a.iw(c[d],d,f)};a.l.prototype.TEa=function(a,c,d,e){if(this.S9()||!d||!e)return{index:a,L_:!1};d=this.Ke();if(a>=d||c>=d)return{index:a,L_:!1};d=this.Rc(a);e=this.Rc(c);this.vL(a,e);e.IB(a);this.vL(c,d);d.IB(c);return{index:c,L_:c!==a}};a.l.prototype.GW=function(b,c,d,e){d=d||{};var f=void 0===d.add?!0:d.add,
h=void 0===d.remove?!0:d.remove,k=void 0===d.merge?!0:d.merge,g=[],m=null,r;c&&(b=this.parse(b));r=Array.isArray(b)?b:[b];if(e){var t=this;return this.$f(function(){return t.Ksa(r,t.Xd(),d,h,f,k)})}c=!1;for(b=0;b<r.length;b+=1)if(m=this.Aea(this.fE(r[b],d,!0),f,k,e),-1!==m){var m=this.TEa(m,b,h,f),s=m.index;m.L_&&(c=!0);-1===g.indexOf(s)&&g.push(s)}c&&this.Kc(d.silent,a.ka.O.SORT,this,d.add?{add:!0}:null,null);a.l.Xba(this,this.Xd(),h,g,d)};a.l.prototype.Ksa=function(b,c,d,e,f,h){var k=[],g,m=this;
return new Promise(function(r,t){function s(a){return new Promise(function(c,e){m.Aea(m.fE(b[a],d,!0),f,h,!0).then(function(b){-1!==b&&k.push(b);c(a+1)},e)})}var q=Promise.resolve(0);for(g=0;g<b.length;g+=1)q=q.then(s);q.then(function(){a.l.Xba(m,c,e,k,d);r(void 0)},t)})};a.l.prototype.Aea=function(a,c,d,e){function f(e,h,k){var f=h?h.index:-1;if(h&&h.m){if(d){var g={merge:d};if(k)return new Promise(function(c){e.nq(a,g,!1,!0).then(function(){c(f)})});e.add(a,g)}}else if(c){if(k)return new Promise(function(c){e.nq(a,
g,!1,!0).then(function(){c(e.vf()-1)})});e.add(a);f=e.vf()-1}return f}if(e||this.Ib()){var h=this;return new Promise(function(c){h.Rk(a,{silent:!0},e).then(function(a){f(h,a,!0).then(function(a){c(a)})})})}var k=this.Rk(a);return f(this,k,!1)};a.l.prototype.toJSON=function(){var a=[];this.ki("toJSON");this.Xd().forEach(function(c){a.push(c.toJSON())});return a};a.b.g("Collection.prototype.toJSON",{toJSON:a.l.prototype.toJSON});a.l.prototype.first=function(a,c){var d=this.Yh(c),e=this.vf(),f=[];a?
e=a:a=1;d=this.Ib()||d;if(1===a){if(d){var h=this;return this.$f(function(){return h.uS(0,null)})}return 0<this.Ke()?this.Rc(0):null}e>this.Ke()&&(!this.Ib()||this.Rs())&&(e=this.Ke());if(d)return h=this,this.$f(function(){return h.Fx(0,e)});for(d=0;d<e;d+=1)f.push(this.Rc(d));return f};a.b.g("Collection.prototype.first",{first:a.l.prototype.first});a.l.prototype.indexOf=function(a,c){var d=this.Yh(c);if(this.Ib()||d){var e=this;return this.$f(function(){return e.Rk(a,null,!0).then(function(a){return a.index})})}return this.Rk(a).index};
a.b.g("Collection.prototype.indexOf",{indexOf:a.l.prototype.indexOf});a.l.prototype.contains=function(a,c){var d=this.Yh(c);if(this.Ib()||d){var e=this;return this.$f(function(){return e.Rk(a,null,!0).then(function(a){return-1<a.index})})}return-1<this.Rk(a).index};a.b.g("Collection.prototype.contains",{contains:a.l.prototype.contains});a.l.prototype.Kha=a.l.prototype.contains;a.b.g("Collection.prototype.include",{Kha:a.l.prototype.Kha});a.l.prototype.fAa=function(a){a=this.k8(a);return void 0!==
a?a.index:-1};a.l.prototype.pop=function(a){var c=this.Yh(a);if(this.Ib()||c){var d=this;return this.at(this.vf()-1,{deferred:c}).then(function(c){d.remove(c,a);return c})}c=this.at(this.vf()-1);this.remove(c,a);return c};a.b.g("Collection.prototype.pop",{pop:a.l.prototype.pop});a.l.prototype.push=function(a,c){var d=this.Yh(c);this.Wv(1);return this.BD(this.nq(a,c,!1,d))};a.b.g("Collection.prototype.push",{push:a.l.prototype.push});a.l.prototype.lastIndexOf=function(b,c){var d;this.ki("lastIndexOf");
void 0===c&&(c=0);for(d=this.vf()-1;d>=c;d-=1)if(a.b.kC(b,this.at(d)))return d;return-1};a.b.g("Collection.prototype.lastIndexOf",{lastIndexOf:a.l.prototype.lastIndexOf});a.l.prototype.S8=function(a){return void 0===a?[]:a.split(",")};a.l.Iva=function(b){b=Array.isArray(b)?b:[b];var c="",d,e,f,h;for(f=0;f<b.length;f++){d=b[f];for(h in d)if(d.hasOwnProperty(h))for(var k=Array.isArray(d[h])?d[h]:[d[h]],l=0;l<k.length;l++){if(a.C.A0(k[l])){e=k[l].value;var m=null,m=k[l].comparator,m=g.isFunction(m)?
m(null,h,e):m;e=h+m+e}else e=h+"\x3d"+d[h];c+=e+"+"}c=c.substring(0,c.length-1)+","}return","===c.substring(c.length-1)?c.substring(0,c.length-1):c};a.l.prototype.Kla=function(b){var c={},d;for(d in b)b.hasOwnProperty(d)&&(c[d]=b[d]);if((b=this.comparator)&&a.cb.Re(b)){b=this.S8(b);for(d=0;d<b.length;d++)c.sort=0===d?b[d]:c.sort+(","+b[d]);c.sortDir=this.U8()}this.Ib()&&(c[a.l.If]=this.Go(c));return c};a.l.prototype.vla=function(){if(g.isFunction(this.customURL))return!0;var b=this.s0(null);return a.l.wq(b)};
a.l.prototype.s0=function(b){var c=a.C.Sr(this,"url");if(this.Ib()){var d=b.all,e=null;e=d?(e=this.totalResults)?e:this.Go(b):this.Go(b);c=c&&-1<c.indexOf("?")?c+"\x26":c+"?";c+="limit\x3d"+e;d||(a.l.wq(b.startIndex)&&(c+="\x26offset\x3d"+b.startIndex),b.startID&&(c+="\x26fromID\x3d"+b.startID),b.since&&(c+="\x26since\x3d"+b.since),b.until&&(c+="\x26until\x3d"+b.until));b.query&&(b=a.l.Iva(b.query))&&0<b.length&&(c+="\x26q\x3d"+b);if((b=this.comparator)&&a.cb.Re(b))for(b=this.S8(b),d=this.U8(),e=
0;e<b.length;e++)c=0===e?c+("\x26orderBy\x3d"+b[e]+":"+d):c+(","+b[e]+":"+d);c+="\x26totalResults\x3dtrue"}return c};a.l.prototype.U8=function(){return-1===this.sortDirection?"desc":"asc"};a.l.prototype.Nr=function(b,c,d){return a.sync(b,c,d)};a.b.g("Collection.prototype.sync",{Nr:a.l.prototype.Nr});a.l.If="fetchSize"});